#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

int main()
{
    int year, month;
    while (scanf("%d%d", &year, &month) != EOF)
        if (month % 2 == 1)
        {
            if (month < 8)
                printf("%d\n", 31);
            else
                printf("%d\n", 30);
        }
        else
        {
            if (month < 8)
            {
                if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 4 == 0))
                    printf("%d\n", 29);
                else if (month == 2)
                    printf("%d\n", 28);
                else
                    printf("%d\n", 30);
            }
            else
                printf("%d", 31);
        }

    return 0;
}